<?php $this->load->view('common/header');?>
<?php echo admin_js_url('vip-order');?>
<body>
<?php $this->load->view('common/user_center');?>
<div class="main_box">
    <?php $this->load->view('common/menu');?>
    <div class="right_box f_r">
        <div class="title">
            <span class="f_l">下单</span>
        </div>
        <div class="add_order">
            <table>
                <tr>
                    <th class="w140">分类</th>
                    <th class="w140">产品名称</th>
                    <th class="w140">规格</th>
                    <th class="w140">单价</th>
                    <th class="w140">制作工艺</th>
                    <th class="w140">料号</th>
                    <th class="w140 operating">下单数量</th>
                    <th class="w140">操作</th>
                </tr>
                <tr>
                    <td>
                        <select name="category_id[]" class="category_id">
                            <option value="0">产品类型</option>
                            <?php if(isset($cates)){?>
                                <?php foreach ($cates as $k => $v) {?>
                                    <option value="<?php echo $v['id'] ?>"><?php echo $v['category_name'] ?></option>
                                <?php  }?>
                            <?php }?>
                        </select>
                    </td>
                    <td>
                        <select name="product_id[]" class="product_id" size="1">
                            <option value="0">选择产品</option>
                        </select>
                    </td>
                    <td class="w140 good_guige_box"></td>
                    <td class="w140 good_price_box"></td>
                    <td class="w140 good_gongyi_box"></td>
                    <td class="w140 good_part_number"></td>
                    <td class="w140 operating good_num_box">
                        <input placeholder="请输入数量" name="good_mum[]" value="" price="">
                    </td>
                    <td class="w140">
                        <a href="javascript:;" class="del_clone_box">删除</a>
                    </td>
                </tr>
            </table>
            <table id="info_box">
                <tr>
                    <td colspan="7">
                        <a href="javascript:;" class="more_add" id="more_add">继续添加</a>
                    </td>
                </tr>
                <tr>
                    <td colspan="7">
                        <div class="select_a">
                            开票：
                            <label class="is_kaipiao" type="1">
                                <i class="ico"></i>是（<?php echo $kaipiao_fee;?>%税点）
                            </label>
                            <label class="on is_kaipiao" type="2">
                                <i class="ico"></i>否
                            </label>
                        </div>
                        <div class="select_a">
                            送货：
                            <label class="is_songhuo" type="1">
                                <i class="ico"></i>是（<?php echo $service_tax;?>%税点）
                            </label>
                            <label class="on is_songhuo" type="2">
                                <i class="ico"></i>否
                            </label>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="7">
                        <div class="add_tit">
                            交货日期
                        </div>
                        <input placeholder="请选择交货日期" class="good_date" id="good_date">
                    </td>
                </tr>
                <tr>
                    <td colspan="7">
                        <div class="add_tit">
                            <a href="<?php echo site_url('vip/user/address');?>">【管理】</a>
                            送货地址
                        </div>

                        <div class="add_list">
                            <?php if(isset($address['dress_uname'])){ ?><p><?php echo $address['dress_uname'];?>&nbsp;&nbsp;<?php echo $address['dress_utel'];?></p><?php } ?>
                            <span><?php echo $address['dress_city'];?></span>
                        </div>

                    </td>
                </tr>
                <tr>
                    <td colspan="7">
                        <textarea placeholder="您可以添加备注" id="remark"></textarea>
                    </td>
                </tr>
                <tr>
                    <td colspan="7">
                        <a href="javascript:;" id="order_do" class="nav">确定下单</a>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
<div style="display: none" id="order_box_clone">
    <table>
        <tr>
            <td class="w140">
                <select name="category_id[]" class="category_id">
                    <option value="0">产品类型</option>
                    <?php if(isset($cates)){?>
                        <?php foreach ($cates as $k => $v) {?>
                            <option value="<?php echo $v['id'] ?>"><?php echo $v['category_name'] ?></option>
                        <?php  }?>
                    <?php }?>
                </select>
            </td>
            <td class="w140">
                <select name="product_id[]" class="product_id" size="1">
                    <option value="0">选择产品</option>
                </select>
            </td>
            <td class="w140 good_guige_box"></td>
            <td class="w140 good_price_box"></td>
            <td class="w140 good_gongyi_box"></td>
            <td class="w140 good_part_number"></td>
            <td class="w140 operating good_num_box">
                <input placeholder="请输入数量" name="good_mum[]" value="" price="">
            </td>
            <td class="w140">
                <a href="javascript:;" class="del_clone_box">删除</a>
            </td>
        </tr>
    </table>
</div>
<?php echo admin_js_url('laydate');?>
<script type="text/javascript">
    $(function () {
        laydate.render({
            elem: '#good_date' //指定元素
        });
        $("#more_add").click(function () {
            var addItem = $("#order_box_clone").children().clone(true).show();
            $('#info_box').before(addItem);
        });
        $(".del_clone_box").click(function () {
            $(this).parent().parent().parent().fadeOut();
        });

    });
    $(document).on('click touchend','#order_do',function(){
        var good_mum =[];
        $("input[name='good_mum[]']").each(function(){
            if($(this).val() != ''){
                good_mum.push($(this).val());
            }

        });
        var category_id =[];
        // $("select[name='category_id[]'").each(function(){
        $(".category_id").each(function(){
            if($(this).val()> 0){
                category_id.push($(this).val());
            }
        });
        var product_id =[];
        // $("select[name='product_id[]'").each(function(){
        $(".product_id").each(function(){
            if($(this).val()> 0){
                product_id.push($(this).val());
            }
        });
        var is_kaipiao=$('.is_kaipiao.on').attr('type');
        var is_songhuo=$('.is_songhuo.on').attr('type');
        var remark=$('#remark').val();
        var good_date=$('#good_date').val();
        var URL= baseurl+"index.php/vip/orders/create";
        $.ajax({
            type: "post",
            url: URL,
            dataType:'json',
            data: {
                'good_mum':good_mum,
                'product_id':product_id,
                'category_id':category_id,
                'is_songhuo':is_songhuo,
                'is_kaipiao':is_kaipiao,
                'remark':remark,
                'good_date':good_date,
                'csrf_test_name': ci_csrf_token()
            },
            success: function(data){
                if(data.status == 200){
                    window.location.href = data.url;
                }else{
                    layer.msg(data.msg);
                    return false;
                }

            }
        });
    });

    $(".is_kaipiao").click(function () {
        $(this).addClass("on");
        $(this).siblings().removeClass("on");
    });
    $(".is_songhuo").click(function () {
        $(this).addClass("on");
        $(this).siblings().removeClass("on");
    });
</script>
<!--]] user -->
<!-- coypright [[-->
<?php $this->load->view('common/footer');?>
<!--]] coypright -->
</body>
</html>
